public class Complex {
	//成员变量
	int realPart;//实数部分
	int imagePart;//虚数部分
	
	//构造函数
	Complex(){//无参
		realPart=0;
		imagePart=0;
	}
	Complex(int r,int i){//有参
		realPart=r;
		imagePart=i;
	}
	
	//相加
	Complex complexADD(Complex c) {
		Complex ret=new Complex();
		ret.realPart=this.realPart+c.realPart;
		ret.imagePart=this.imagePart+c.imagePart;
		return ret;
	}
	
	//相减
	Complex complexSUB(Complex c) {
		Complex ret=new Complex();
		ret.realPart=this.realPart-c.realPart;
		ret.imagePart=this.imagePart-c.imagePart;
		return ret;
	}
	
	//重写toString方法
	public String toString(){
		return realPart+"+"+imagePart+"i";
	}

	public static void main(String[] args) {
		//用复数类实例化对象
		Complex a=new Complex(3,5);
		Complex b=new Complex(2,3);
		
		//相加
		Complex c=a.complexADD(b);
		//输出
		System.out.println(a+"与"+b+"相加的结果为："+c);
		//相减
		Complex d=a.complexSUB(b);
		//输出
		System.out.println(a+"与"+b+"相减加的结果为："+d);
	}

}
